package com.carkeeper.controller;

import com.carkeeper.pojo.ComponentBrandPO;
import com.carkeeper.service.ComponentBrandService;
import com.carkeeper.vo.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping("/componentBrand")
public class ComponentBrandController {
    @Autowired
    private ComponentBrandService componentBrandService;

    /*获取配件品牌分页数据*/
    @GetMapping
    public Pager<ComponentBrandPO> queryPage(@RequestParam(value = "page",required = false,defaultValue = "1") Long page,
                                             @RequestParam(value = "pageSize",required = false,defaultValue = "10") Long pageSize,
                                             @RequestParam(value = "brandName",required = false) String brandName,
                                             @RequestParam(value = "code",required = false) String code) {

        return new Pager(componentBrandService.query(code, brandName, page, pageSize));
    }

    /*获取配件品牌详情*/
    @GetMapping("/{id}")
    public ComponentBrandPO queryById(@PathVariable long id){
        ComponentBrandPO componentBrandPO = componentBrandService.query(id);
        return componentBrandPO;
    }

    /*新增配件品牌*/
    @PostMapping
    public Boolean create(@RequestBody ComponentBrandPO po) {
        componentBrandService.create(po);
        return true;
    }

    /*更新配件品牌信息*/
    @PutMapping("/{id}")
    public Boolean update(@PathVariable Long id,
                          @RequestBody ComponentBrandPO po) {
        componentBrandService.update(id, po);
        return true;
    }

    /*根据ID删除配件品牌*/
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable long id) {
        componentBrandService.delete(id);
        return true;
    }


}
